<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .menus {
        display: flex;
        justify-content: center;
        align-items: center;
        line-height: 20px;
        border: solid 1px;
        width: 200px;
        position: relative;
        cursor: pointer;
      }
      .menus-name:hover {
        background-color: yellow;
      }
      .menus-list {
        list-style: none;
        padding: 0;
        margin: 0;
        border: solid 1px;
        /* display: flex; */
        flex-direction: column;
        margin-bottom: 5px;
        position: absolute;
        left: 0;
        right: 0;
        top: 20px;
        display: none;
      }
    </style>
  </head>
  <body>
    <div class="menus" id="menu">
      <div class="menus-name" id="menusName">菜单</div>
      <ul class="menus-list" id="menusList">
        <li>删除</li>
        <li>添加</li>
        <li>编辑</li>
      </ul>
    </div>
    <script>
      const menusName = document.getElementById("menusName");
      const menusList = document.getElementById("menusList");
      menusName.onclick = function () {
        // 计算样式
        const style = getComputedStyle(menusList);
        if (style.display === "none") {
          menusList.style.display = "flex";
        } else {
          menusList.style.display = "";
        }
      };
    </script>
  </body>
</html>
